package de.baumann.browser.adapter;

import android.annotation.SuppressLint;
import android.widget.TextView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;

import de.baumann.browser.R;
import de.baumann.browser.api.net.vo.Order;

/**
 * @author:
 * @date:2019/1/4 16:49
 * @discription: 算力包订单适配器
 */
public class HashOrderAdapter extends BaseQuickAdapter<Order, BaseViewHolder> {
    private int itemType;
    private OnOrderClickListener onOrderClickListener;

    public HashOrderAdapter(int layoutResId, int itemType) {
        super(layoutResId);
        this.itemType = itemType;
    }

    public void setOnOrderClickListener(OnOrderClickListener onOrderClickListener) {
        this.onOrderClickListener = onOrderClickListener;
    }

    @Override
    protected void convert(BaseViewHolder helper, Order item) {
        processCommData(helper, item);
        if (itemType == 0) {
            helper.getView(R.id.btnHashCancel).setOnClickListener(view -> {
                if (onOrderClickListener != null) {
                    onOrderClickListener.onCancelOrder(item.getTradeNo());
                }
            });

            helper.getView(R.id.btnHashPain).setOnClickListener(view -> {
                if (onOrderClickListener != null) {
                    onOrderClickListener.onRepaid(item.getTradeNo(), item.getPayMode());
                }
            });
        }
    }

    @SuppressLint("SetTextI18n")
    private void processCommData(BaseViewHolder helper, Order item) {
        helper.setText(R.id.tvHashUnpainCode, mContext.getString(R.string.order_code) + item.getOrderId());
        helper.setText(R.id.tvHashValue, item.getHashValue() + mContext.getString(R.string.hash_packet));
        helper.setText(R.id.tvHashUnpainTime, item.getOrderTime());
        TextView tvHashUnpainAmount = helper.getView(R.id.tvHashUnpainAmount);
        tvHashUnpainAmount.setText(item.getOrderAmount() + " ODIN");
    }

    public interface OnOrderClickListener {
        void onCancelOrder(String tradeNo);

        void onRepaid(String tradeNo, int patMode);
    }

}
